import FGUI_PGameMain from "src/FGUI/GameMain/FGUI_PGameMain";
import AudioProxy from "src/Game/Manager/AudioProxy";
import { EUIEvent } from "src/Game/MesEvent/EUIEvent";
import { EMusics } from "src/Game/ResE/EMusics";
import { ESounds } from "src/Game/ResE/ESounds";
import { MarsJoy } from "src/Ldz_GameCore/PlayerCore/MarsJoy";
import BaseSingleUICon from "src/_T/D2/FGUI/BaseSingleUICon";
import { EUILayer } from "src/_T/D2/FGUI/EUILayer";
import MesManager from "src/_T/Mes/MesManager";
import InstanceT from "src/_T/Ts/InstanceT";
import LayaUtils from "src/_T/Utils/LayaUtils";

@InstanceT.DecorateInstance()
//解锁物品的弹出界面
export class P_UIGameMainPoxy extends BaseSingleUICon<FGUI_PGameMain> {
    public static readonly instance: P_UIGameMainPoxy;
    protected _UI = FGUI_PGameMain;
    protected _layer = EUILayer.Main;
    private constructor() {
        super();
    }
    Isshow = false;
    Init() {
        MesManager.on(EUIEvent.ShowUIMain, this, this.Show);
    }
    //显示回调
    protected _onShow(_ifNew: boolean, ...par) {
        //初始化 虚拟摇杆
        let Joy = new MarsJoy();
        Joy.Init(this.ui);
        this.ui.m_StarPlay.onClick(this, this.PlayMusic);
        this.ui.m_StarPlayBgm.onClick(this, this.StarPlayBgm);
        this.ui.m_StarPlaySound.onClick(this, this.m_StarPlaySound);
    }
    iSLoop: boolean = true;
    PlayMusic() {
        //
        this.StarStep();
    }
    StarStep() {
        if (!this.iSLoop) return;
        this.iSLoop = false;
        Laya.timer.frameLoop(0.35, this, this.AudioLoop);
    }

    CurTime: number = 0;
    CurTIme2: number = 0;
    AudioLoop() {
        if (this.iSLoop) { return; }
        console.log("循环中");
        this.CurTime -= (LayaUtils.deltaTime / 1000);
        this.CurTIme2 -= (LayaUtils.deltaTime / 1000);
        if (this.CurTime < 0) {
            this.CurTime = 2;
            AudioProxy.instance.StopSound_Bgm(ESounds.common_melee_attack);
        } else {
            if (this.iSLoop) { return; }
            AudioProxy.instance.PlaySound_Bgm(ESounds.common_melee_attack);
        }
        if (this.CurTIme2 < 0) {
            this.CurTIme2 = 1;
            AudioProxy.instance.playSound(ESounds.archer_attack_1, 1);
        }
    }

    StarPlayBgm() {
        console.log("主场景");
        AudioProxy.instance.playBGM(EMusics.home_background);
    }

    m_StarPlaySound() {
        console.log("游戏结束")
        Laya.timer.clear(this, this.AudioLoop);
        this.iSLoop = true;
        AudioProxy.instance.playSound(ESounds.game_win, 1);
        AudioProxy.instance.StopSound_Bgm(ESounds.common_melee_attack);

    }

}